package com.glepoch.springbootsecuritymybatis.controller.menu;

import com.glepoch.springbootsecuritymybatis.bean.Menu;
import com.glepoch.springbootsecuritymybatis.bean.PageResultVO;
import com.glepoch.springbootsecuritymybatis.bean.PageVO;
import com.glepoch.springbootsecuritymybatis.service.menu.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @author ygl
 * @description 菜单
 * @date 2021年08月24日 20:18
 */
@Controller
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    MenuService menuService;

    @GetMapping("/toMenuPage")
    public String findMenuPage(HttpServletResponse response) {
        return "menu/menuPage";
    }

    @PostMapping("/findMenuPage")
    @ResponseBody
    public PageResultVO<List<Menu>> findMenuPage(@RequestBody PageVO<Menu> menuPageVO) {
        List<Menu> menuPage = menuService.findMenuPage(menuPageVO);
        PageResultVO success = PageResultVO.success();
        success.setTotal(50L);
        success.setData(menuPage);
        return success;
    }

    @GetMapping(value = "/findMenuByUserId/{userId}",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public List<Menu> findMenuByUserId(@PathVariable("userId") Long userId) {
        List<Menu> menus=menuService.findMenuByUserId(userId);
        return menus;
    }
}
